$('#parse').click(function(){


    var commandStack = new Array();
    
    var serviceObj= new Service();

    // Add Service Object
    $('.right').find('.serviceElement input').each(function(){

        serviceObj.description = $(this).val();
        serviceObj.level= $('#level').val();
        serviceObj.type= $('#type').val();


    });

    $('.right').find('.attribute_element').each(function(){
        var attribute = new Attribute();
        $(this).find('.attributeDesc').each(function(){



            attribute.description=$(this).val();



            serviceObj.attribute.push(attribute);
        });

        parseAspect($(this), attribute);


    });






    $('#op').html(JSON.stringify(serviceObj));

    $.ajax({
        type:"POST",
        datatype : "json",
        contentType: "application/json; charset=utf-8",
        url:"/SMAdmin/rest/json/services/create",
        data:JSON.stringify(serviceObj),
        success:function(){
            alert(data);
        },
        error:function(){
            alert(data);
        }
    });



});

function parseAspect(thisObj, attribute){

    thisObj.find('.aspectItem').each(function(){
        var aspectConf = new AspectConf();
			
        $(this).find('.required').each(function(){
            aspectConf.required=($(this).is(':checked'));
        });
			
        $(this).find('.readOnly').each(function(){
            aspectConf.readOnly=($(this).is(':checked'));
        });
			
        $(this).find('.defaultValue').each(function(){
            aspectConf.defaultValue=($(this).is(':checked'));
        });
			
        var aspect = new Aspect();
			
        $(this).find('.desc').each(function(){
				
            aspect.name=($(this).val());
            aspect.description=($(this).val());
        });
			
			
        aspectConf.aspectListGroup = new AspectListGroup();
        
        parseAspectList($(this), aspectConf.aspectListGroup);
			
        aspectConf.aspect= aspect;
			
        attribute.aspectConf.push(aspectConf);
			
        //
    });
}

function parseAspectList(thisObj, aspectListGroup){

    parseAspectListType(thisObj, aspectListGroup,'dropDownElementList');
    parseAspectListType(thisObj, aspectListGroup,'checkboxElementList');

}

function parseAspectListType(thisObj, aspectListGroup, type){

    thisObj.find('.'+type).each(function(){
	
        var aspectListGroupConf = new AspectListGroupConf();
        aspectListGroupConf.id = new AspectListGroupConfId();
        aspectListGroupConf.id.aspectList = new AspectList();
		
        aspectListGroupConf.id.aspectList.optionDescription = $(this).val();
        aspectListGroupConf.id.aspectList.optionValue = $(this).val();
		
        
		
		
        aspectListGroup.aspectListGroupConfs.push(aspectListGroupConf);
	
    });

}


